package com.ruoyi.web.controller.ring.app;

import cn.hutool.core.convert.Convert;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.RingMyOtherSet;
import com.ruoyi.ring.domain.dto.RingMyOtherSetDTO;
import com.ruoyi.ring.domain.vo.RingMyOtherSetVO;
import com.ruoyi.ring.service.IRingMyOtherSetService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 我的戒指其他设置 app
 * 
 * @author liuwp
 * @date 2025-10-15
 */
@RestController
@RequestMapping("/ring/app/ring_my_other_set")
public class AppMyOtherSetController extends BaseController
{
    @Resource
    private IRingMyOtherSetService ringMyOtherSetService;


    /**
     * 获取我的戒指其他设置详细信息 app
     */
    @GetMapping(value = "/query-my-other-set")
    public AjaxResult queryMyOtherSet()
    {
        RingMyOtherSetVO vo = new RingMyOtherSetVO();
        RingMyOtherSet myReminderSet = ringMyOtherSetService.selectOneRingMyOtherSet(Builder.of(RingMyOtherSet::new).with(RingMyOtherSet::setUserId, SecurityUtils.getUserId()).build());
        if(myReminderSet != null){
            vo = Convert.convert(RingMyOtherSetVO.class,myReminderSet);
        }
        return AjaxResult.success(vo);
    }

    /**
     * 编辑我的戒指其他设置 app
     */
    @Log(title = "我的戒指其他设置", businessType = BusinessType.INSERT)
    @PostMapping("/operation-my-other-set")
    public AjaxResult operationMyOtherSet(@RequestBody RingMyOtherSetDTO dto)
    {
        RingMyOtherSet ringMyOtherSet = Convert.convert(RingMyOtherSet.class,dto);
        RingMyOtherSet myReminderSet = ringMyOtherSetService.selectOneRingMyOtherSet(Builder.of(RingMyOtherSet::new).with(RingMyOtherSet::setUserId, SecurityUtils.getUserId()).build());
        if(myReminderSet == null){
            ringMyOtherSet.setUserId(SecurityUtils.getUserId());
            ringMyOtherSet.setCreateTime(new Date());
            return toAjax(ringMyOtherSetService.insertRingMyOtherSet(ringMyOtherSet));
        }else {
            ringMyOtherSet.setId(myReminderSet.getId());
            return toAjax(ringMyOtherSetService.updateRingMyOtherSet(ringMyOtherSet));
        }
    }

}
